const pkg = require('./package')
const crypto = require('crypto')
const VERSION = crypto.createHash('md5').update(String(+new Date)).digest('hex');

const fs = require('fs');

//如果本地存在local.config.js的话，会与当前文件合并
let localConfig = {};

//测试环境用到的plugin
switch (process.env.PROJECT_ENV){
  case 'test': //测试环境
    break;
  case 'production': //正式环境
    break;
  case 'development': //开发环境
    try{
      let local = './local.config.js';
      fs.readFileSync(local);
      localConfig = require(local);
    }catch(e){}
    break;
}

module.exports = {
  mode: 'spa',
  env: Object.assign({
    version:VERSION,
  },localConfig.env || {}),
  server: {
    port: 3000, // default: 3000
    host: '0.0.0.0', // default: localhost,
  },
  /*
  ** Headers of the page
  */
  head: {
    title: '乐马国际会',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width,initial-scale=1.0,maximum-scale=1,user-scalable=0' },
      { hid: 'HTTP-EQUIV', name: 'HTTP-EQUIV', content: 'no-cache' },
      { hid: 'Cache-Control', name: 'Cache-Control', content: 'no-cache' },
      { hid: 'Expires', name: 'Expires', content: '0' },
      { hid: 'description', name: 'description', content: '乐马国际会' },
      { hid: 'cache', name: 'page-cache', content: VERSION },
    ],
    link: [
      {
        rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],
    script: [
      { src: `/static/config.js?v=${VERSION}` },
      { src: '/static/js/jquery.min.js' },
      { src: '/static/js/webuploader.html5only.js' }
    ],
  },

  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#138CDD' },

  /*
  ** Global CSS
  */
  css: [
    '~/assets/less/global.less'
  ],

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    '~/plugins/axios',
    '~/plugins/error',
    '~/plugins/toast',
    '~/plugins/alert',
    '~/plugins/url',
    '~/plugins/awe-dnd',
    '~/plugins/tools',
    '~/plugins/ui',
  ].concat(localConfig.plugins || []),

  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://github.com/nuxt-community/axios-module#usage
    // '@nuxtjs/axios'
  ],

  router: {
    middleware: ['authenticated','clear','init','socket']
  },
  /*
  ** Build configuration
  */
  build: {
    // cache: true,
    // parallel: true,
    vendor:['axios','~/plugins/axios'],
    publicPath:'/static/',
    styleResources: {
      less: [
        './assets/less/module/var.less',
        './assets/less/module/mixin.less'
      ]
    },
    /*
    ** You can extend webpack config here
    */
    extend(config, ctx) {
    },
    babel:{
      "plugins": [["component",
        {
          "libraryName": "mint-ui",
          "style": true
        }
      ]]
    },
    postcss: {
      // 添加插件名称作为键，参数作为值
      // 使用npm或yarn安装它们
      plugins: {
        // 通过传递 false 来禁用插件
        "postcss-import": {},
        "postcss-url": {},
        // to edit target browsers: use "browserslist" field in package.json
        "autoprefixer": {},
        "postcss-px2rem-exclude": {
          "remUnit": 75,
           exclude: /node_modules/i
        },
      },
    }
  }
}
